package com.zhiyi.coco.controller;

import com.zhiyi.coco.entity.Type;
import com.zhiyi.coco.service.TypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "TypeController", description = "饮品类型信息编辑")
@RestController
@RequestMapping("/type")
@Log4j
public class TypeController {
    @Autowired
    private TypeService service;

    /**
     * @return 根据饮品编号获取饮品类型
     */
    @ApiOperation("根据饮品编号获取饮品类型")
    @ResponseBody
    @RequestMapping("/getInfoById/{id}")
    public Type getInfoById(@PathVariable Integer id) {
        Type food = service.getInfoById(id);
        if(food==null){
            return null;
        }
        return food;
    }

    /**
     * @return 根据饮品编号获取饮品类型
     */
    @ApiOperation("根据饮品编号获取饮品类型")
    @ResponseBody
    @RequestMapping("/getAllType")
    public List<Type> getAllType() {
        List<Type> t = service.getAllType();
        if(t==null){
            return null;
        }
        return t;
    }
}
